﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace WFExtended.Twitter
{
    /// <summary>
    /// Place
    /// </summary>
    [DataContract]
    public class Place
    {
        /// <summary>
        /// Gets or sets the bounding box.
        /// </summary>
        /// <value>
        /// The bounding box.
        /// </value>
        [DataMember(Name = "bounding_box")]
        public BoundingBox BoundingBox { get; set; }

        /// <summary>
        /// Gets or sets the attributes.
        /// </summary>
        /// <value>
        /// The attributes.
        /// </value>
        [DataMember(Name = "attributes")]
        public GeoAttributes Attributes { get; set; }

        /// <summary>
        /// Gets or sets the contained within.
        /// </summary>
        /// <value>
        /// The contained within.
        /// </value>
        [DataMember(Name = "contained_within")]
        public List<ContainedWithin> ContainedWithin { get; set; }

        /// <summary>
        /// Gets or sets the country.
        /// </summary>
        /// <value>
        /// The country.
        /// </value>
        [DataMember(Name = "country")]
        public string Country { get; set; }

        /// <summary>
        /// Gets or sets the country code.
        /// </summary>
        /// <value>
        /// The country code.
        /// </value>
        [DataMember(Name = "country_code")]
        public string CountryCode { get; set; }

        /// <summary>
        /// Gets or sets the full name.
        /// </summary>
        /// <value>
        /// The full name.
        /// </value>
        [DataMember(Name = "full_name")]
        public string FullName { get; set; }

        /// <summary>
        /// Gets or sets the ID.
        /// </summary>
        /// <value>
        /// The ID.
        /// </value>
        [DataMember(Name = "id")]
        public string ID { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        [DataMember(Name = "name")]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the type of the place.
        /// </summary>
        /// <value>
        /// The type of the place.
        /// </value>
        [DataMember(Name = "place_type")]
        public string PlaceType { get; set; }

        /// <summary>
        /// Gets or sets the URL.
        /// </summary>
        /// <value>
        /// The URL.
        /// </value>
        [DataMember(Name = "url")]
        public string Url { get; set; }

        /// <summary>
        /// Gets the latitude.
        /// </summary>
        /// <value>
        /// The latitude.
        /// </value>
        public string Latitude
        {
            get
            {
                if (BoundingBox != null
                    && BoundingBox.Coordinates != null
                    && BoundingBox.Coordinates.Count() > 0
                    && BoundingBox.Coordinates[0].Count() > 0
                    && BoundingBox.Coordinates[0][0].Count() > 1)
                    return BoundingBox.Coordinates[0][0][1].ToString(new CultureInfo("en-US"));
                else
                    return String.Empty;
            }
        }

        /// <summary>
        /// Gets the longitude.
        /// </summary>
        /// <value>
        /// The longitude.
        /// </value>
        public string Longitude
        {
            get
            {
                if (BoundingBox != null
                    && BoundingBox.Coordinates != null
                    && BoundingBox.Coordinates.Count() > 0
                    && BoundingBox.Coordinates[0].Count() > 0
                    && BoundingBox.Coordinates[0][0].Count() > 1)
                    return BoundingBox.Coordinates[0][0][0].ToString(new CultureInfo("en-US"));
                else
                    return String.Empty;
            }
        }
    }
}
